<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Glbusinessunit extends CI_Controller {

	public function __construct(){
		parent::__construct();
		$this->load->model($this->session->userdata('formodel'));
		$this->load->model('wus');
		$this->load->library('upload');
		$this->load->library('variable');

	}

	public function index(){

		 $this->load->view('layouts/header',$this->variable->load_data($this->session->userdata('title')));

	    $this->load->view($this->session->userdata('formain'));

	    $this->load->view('layouts/footer');

	}

	public function add_glbu(){
		$this->load->view($this->session->userdata('foradd'),array(
	    		'cogs'			=> $this->glbusinessunit_model->get_cogs(),
				'expense'		=> $this->glbusinessunit_model->get_expense(),
				'sales'			=> $this->glbusinessunit_model->get_sales()
	    	));
	}

	public function edit_glbu($id){
		$this->load->view($this->session->userdata('foredit'),array(
	    		'cogs'			=> $this->glbusinessunit_model->get_cogs(),
				'expense'		=> $this->glbusinessunit_model->get_expense(),
				'sales'			=> $this->glbusinessunit_model->get_sales(),
				'glbu'			=> $this->glbusinessunit_model->getBu($id)
	    	));	
	}
	public function view_glbu($id){
		$this->load->view($this->session->userdata('forview'),array(
				'glbu'			=> $this->glbusinessunit_model->getBu($id)
	    	));	
	}

	public function search_bu(){

		echo json_encode($this->glbusinessunit_model->searchData($this->input->post('bu_code'),$this->input->post('bu_name')));

	}

	public function add_bu(){
		$data = array(
				':p_bu_code'			=> $this->input->post('bu_code'),
				':p_bu_name'			=> $this->input->post('bu_name'),
				':p_def_sales_acct_id'	=> $this->input->post('bu_sales'),
				':p_def_cogs_acct_id'	=> $this->input->post('bu_cogs'),
				':p_def_exp_acct_id'	=> $this->input->post('bu_exp'),
				':p_enable_flag'		=> ($this->input->post('glbu_enabled') != "" ? 'Y' : 'N'),
				':p_created_by'			=> $this->session->userdata('user_id'),
				':p_updated_by'			=> $this->session->userdata('user_id')
				);
		$this->glbusinessunit_model->insertData($data);
	}

	public function edit_bu(){
		$data = array(
				':p_bu_code'			=> $this->input->post('bu_code'),
				':p_bu_name'			=> $this->input->post('bu_name'),
				':p_def_sales_acct_id'	=> $this->input->post('bu_sales'),
				':p_def_cogs_acct_id'	=> $this->input->post('bu_cogs'),
				':p_def_exp_acct_id'	=> $this->input->post('bu_exp'),
				':p_enable_flag'		=> ($this->input->post('glbu_enabled') != "" ? 'Y' : 'N'),
				':p_updated_by'			=> $this->session->userdata('user_id'),
				':p_bu_id'	  			=> $this->input->post('bu_id'),
				);
		$this->glbusinessunit_model->updateData($data);
	}
}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */